﻿package visualizer.code
{
	import flash.geom.ColorTransform;
	import flash.events.Event;
	
	public class TestVisualizer extends Visualizer
	{
		// Variables
		
		// Splash Objects
		var splash1:Splash;
		var splash2:Splash;
		var splash3:Splash;
		
		public function TestVisualizer()
		{
			// Initialize Splashes
			splash1 = new Splash();
			addChild(splash1);
			
			splash2 = new Splash();
			addChild(splash2);
			
			splash3 = new Splash();
			addChild(splash3);
			
			splash1.x = 90;
			splash1.y = 250;
			splash2.x = 275;
			splash2.y = 200;
			splash3.x = 451;
			splash3.y = 250;
			
			// Setup Listeners
			addEventListener(Event.ENTER_FRAME, onEnterFrame);
			addEventListener(BeatEvent.LOW_BAND_BEAT, handleLowBeat);
			addEventListener(BeatEvent.MID_BAND_BEAT, handleMidBeat);
			addEventListener(BeatEvent.HIGH_BAND_BEAT, handleHighBeat);
		}
		
		private function onEnterFrame(event:Event)
		{
			trace("Brad onEnterFrame");
			splash1.scaleX = avgVol();
			splash1.scaleY = avgVol();
			splash2.scaleX = avgVol();
			splash2.scaleY = avgVol();
			splash3.scaleX = avgVol();
			splash3.scaleY = avgVol();
		}
		
		override protected function drawFrame()
		{
			
		}
		
		private function handleLowBeat(event:BeatEvent)
		{
			var c:ColorTransform = new ColorTransform();
			c.color = random(0,0xFFFFFF);
			splash1.transform.colorTransform = c;
		}
		
		private function handleMidBeat(event:BeatEvent)
		{
			var c:ColorTransform = new ColorTransform();
			c.color = random(0,0xFFFFFF);
			splash2.transform.colorTransform = c;
		}
		
		private function handleHighBeat(event:BeatEvent)
		{
			var c:ColorTransform = new ColorTransform();
			c.color = random(0,0xFFFFFF);
			splash3.transform.colorTransform = c;
		}
		
		private function random(low:Number=0, high:Number=1):Number
		{
			return Math.floor(Math.random() * (1+high-low)) + low;
		}		
	}
}